<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class MShareFiles extends MModel
{
    
    public static function CreateShareFile($key, $file_id, $expires)
    {
        $sql  = "insert into " . DB_PREFIX . "_share_files(share_key,file_id,expires, ";
        $sql .= "created_at,updated_at) values (";
        $sql .= "\"{$key}\",";
        $sql .= "{$file_id},";
        $sql .= "\"{$expires}\",";
        $sql .= "now(),now())";

        $db_manager = MDbManager::getInstance();
        return $db_manager->insertDb($sql);
    }
    
    
    public static function queryShareByFileId($file_id)
    {
        $db_manager = MDbManager::getInstance();
        $sql = "select * from " . DB_PREFIX . "_share_files where file_id={$file_id} ";
        FXP::trace("function: '{__FUNCTION__}',sql:'{$sql}'");
        
        return $db_manager->selectDb($sql);
    }
    
    
    public static function queryShareByKey($share_key)
    {
        $db_manager = MDbManager::getInstance();
        $sql = "select * from " . DB_PREFIX . "_share_files where share_key=\"{$share_key}\" ";
        FXP::trace("function: '{__FUNCTION__}',sql:'{$sql}'");
        
        return $db_manager->selectDb($sql);
    }
    
    
    public static function updateShareExpiresById($id, $expires) {
        $db_manager = MDbManager::getInstance();
        $sql = "UPDATE " . DB_PREFIX . "_share_files SET expires = {$expires} ";
        $sql .= "WHERE id = {$id} ";
        FXP::trace("handleRemoveObject: ".$sql);
        return $db_manager->updateDb($sql);
    }
}
?>